package com.LeeCode;

import java.util.HashMap;
import java.util.Map;

/**
 * 每个元音包含偶数次的最长子字符串
 */

public class Code1371 {
    public static void main(String[] args) {
        String s = "eleetminicoworoep";
        System.out.println(new Code1371().findTheLongestSubstring(s));
    }

    public int findTheLongestSubstring(String s) {
        String vowels = "aeiou";
        char[] chars = s.toCharArray();
        Map<Integer, Integer> map = new HashMap<>();
        map.put(0, -1);
        int preXor = 0;
        int ans = 0;
        for (int i = 0; i < chars.length; i++) {
            if (vowels.indexOf(chars[i]) != -1) {
                int num = 1 << (chars[i] - 'a');
                preXor ^= num;
            }
            if (map.containsKey(preXor)) {
                ans = Math.max(ans, i - map.get(preXor));
            } else {
                map.put(preXor, i);
            }
        }
        return ans;
    }
}
